package com.crm.jdy.controller.drp;

import com.crm.jdy.common.dto.ProjectInfoDto;
import com.crm.jdy.common.dto.WOrderInfoDto;
import com.crm.jdy.common.pojo.ProjectInfo;
import com.crm.jdy.common.pojo.WOrderInfo;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.drp.WOrderInfoService;
import com.crm.jdy.service.project.ProjectInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.validation.constraints.NotNull;

/**
*
* <p>说明： 采购订单列表信息API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年4月12日
*
*/
@Api(tags = "wOrderInfo", description ="采购订单列表信息")
@RestController
@RequestMapping("/wOrderInfo")
public class WOrderInfoController{

    @Reference(version = "${service.version}", check = false)
    WOrderInfoService wOrderInfoService;

    @RateLimit()
    @ApiOperation("采购订单信息")
    @PostMapping("/seleteWOrderInfo")
    public ResultVo seleteWOrderInfo(@RequestBody WOrderInfoDto wOrderInfoDto){
        PageInfo<WOrderInfo> list = wOrderInfoService.seleteWOrderInfo(wOrderInfoDto);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新采购订单信息")
    @PostMapping("/updateWOrderInfo")
    public ResultVo updateWOrderInfo(@ApiParam(value = "wOrderInfo", required = true)
                                      @Validated @RequestBody WOrderInfo wOrderInfo){
        boolean index = wOrderInfoService.updateWOrderInfo(wOrderInfo);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加采购订单信息")
    @PostMapping("/addWOrderInfo")
    public ResultVo addWOrderInfo(@ApiParam(name = "wOrderInfo", required = false)
                                   @Validated @RequestBody WOrderInfo wOrderInfo){
        boolean list  = wOrderInfoService.addWOrderInfo(wOrderInfo);
        if(list){
            return ResultVo.success("添加成功");
        }
        return ResultVo.failed("添加失败，数据已存在");
    }

    @RateLimit()
    @ApiOperation("删除采购订单信息")
    @DeleteMapping("deleteWOrderInfo/{orderId}")
    public ResultVo deleteWOrderInfo(@NotNull @ApiParam(name = "orderId", value = "orderId", required = true) @PathVariable String orderId){
        boolean b = wOrderInfoService.removeWOrderInfo(orderId);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }


}